package com.ibk.system.call;

import android.app.Activity;
import android.content.Intent;
import android.net.Uri;
import android.os.Bundle;
import android.view.KeyEvent;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;

public class PhoneCallActivity extends Activity {
	EditText mEdtNumber = null;
	LinearLayout mLinearLayout = null;
	Button mButton_dial = null;

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		mLinearLayout = new LinearLayout(this);
		mEdtNumber = new EditText(this);
		mEdtNumber.setText("010-5552-5487");
		mLinearLayout.addView(mEdtNumber);
		mButton_dial = new Button(this);
		mButton_dial.setText("전화걸기");
		mLinearLayout.addView(mButton_dial);
		// 버튼 이벤트
		mButton_dial.setOnClickListener(new View.OnClickListener() {
			public void onClick(View v) {
				performDial();
			}
		});
		setContentView(mLinearLayout);
	}

	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_CALL) {
			performDial();
			return true;
		}
		return false;
	}

	/** 전화걸기 실행 함수 */
	public void performDial() {
		if (mEdtNumber != null) {
			try {
				startActivity(new Intent(Intent.ACTION_CALL, Uri.parse("tel:"
						+ mEdtNumber.getText())));
			} catch (Exception e) {
				e.printStackTrace();
			}
		}
	}
}
